<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .time{
          width: 300px;
          height: 60px;
          margin:0px auto;
          line-height: 60px;
          text-align: center;
          color: red;
          background-color: yellow;
      }
    
    </style>
</head>
<body>
    <div id="time" class="time"></div>
    <script>
        // ***
        // toLocaleString() 方法可根据本地时间把 Date 对象转换为字符串，并返回结果。
        // let time = new Date()
        // console.log(time.toLocaleString());
        // ***

        // setInterval(function(){
        //     var d = new Date();
        //     var time = document.getElementById('time');
        //     //获取当前区域时间并转成字符串
        //     time.innerHTML = d.toLocaleString();
        // },1000);


        setInterval(() => {
            var dTime = new Date();  //获取当前时间
            var time = document.querySelector('.time')

            time.innerHTML = dTime.toLocaleString()
        }, 1000);


    </script>
</body>
</html>